﻿@{
    ViewBag.Title = "文章列表";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@model List<UcAsp.Net.Model.ArticelsViews>
<div class="container-fluid">
    <div class="span2">
        <input type="text" id="searchTitle" placeholder="标题搜索" /></div>
    <div class="span2">
        <span class="btn" id="btnSearch"><i class="icon-search"></i></span>
    </div>
    <div class="row-fluid">
        <div class="widget-box">
            <div class="widget-title">
                <span class="icon"><i class="icon-th"></i></span>
                <h5>
                    类目管理</h5>
            </div>
            <div class="widget-content nopadding">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>
                                类目
                            </th>
                            <th>
                                标题
                            </th>
                            <th>
                                添加时间
                            </th>
                            <th>
                                操作
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (UcAsp.Net.Model.ArticelsViews v in Model)
                        {
                            <tr>
                                <td>@v.CategorieName
                                </td>
                                <td>
                                    @v.Title
                                </td>
                                <td>
                                    @v.AddDatetime.ToString("yyyy-MM-dd")
                                </td>
                                <td>
                                    <a class="btn" href="/Admin/ArticlesPageManager?ID=@v.ID&CID=@v.CategorieID">分页列表</a>
                                    <a class="btn" href="/Admin/ArticlesManager?ID=@v.ID&CID=@v.CategorieID">编辑</a><span class="btn recommand" data-id="@v.ID"><i class="@if (v.IsRecommend)
                                                                                                                                                                         {<text>icon-thumbs-up</text>}
                                                                                                                                                                         else
                                                                                                                                                                         {<text>icon-thumbs-down</text>}"></i>@if (v.IsRecommend)
                                                                                                                                                                                                              {<text>取消</text>}
                                                                                                                                                                                                              else
                                                                                                                                                                                                              {<text>推荐</text>}</span><span class="btn release" data-id="@v.ID"><i class="@if (v.IsRelease)
                                                                                                                                                                                                                                                                                                                                  {<text>icon-thumbs-up</text>}
                                                                                                                                                                                                                                                                                                                                  else
                                                                                                                                                                                                                                                                                                                                  {<text>icon-thumbs-down</text>}"></i>@if (v.IsRelease)
                                                                                                                                                                                                                                                                                                                {<text>下架</text>}
                                                                                                                                                                                                                                                                                                                else
                                                                                                                                                                                                                                                                                                                {<text>上架</text>}</span><span class="btn delete" data-id="@v.ID">删除</span>
                                </td>
                            </tr>
                        }
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="4">
                                <div class="btn-group">
                                    <a class="btn" href="/admin/articles?PageIndex=1&@ViewData["CID"]@ViewData["UserID"]">
                                        <i class="icon-step-backward"></i></a><a class="btn" href="/admin/articles?PageIndex=@ViewData["Pre"]@ViewData["CID"]@ViewData["UserID"]">
                                            <i class="icon-backward"></i></a>
                                    @if (int.Parse(ViewData["PageCount"].ToString()) < 20)
                                    {
                                        for (int i = 1; i < int.Parse(ViewData["PageCount"].ToString()) + 1; i++)
                                        { 
                                        <a class="btn" href="/admin/articles?PageIndex=@i@ViewData["CID"]@ViewData["UserID"]">
                                            @i.ToString()
                                        </a>
                                        }
                                    }
                                    else
                                    {
                                        int pagecount = (int.Parse(ViewData["Next"].ToString()) + 10) > int.Parse(ViewData["PageCount"].ToString()) ? int.Parse(ViewData["PageCount"].ToString()) : (int.Parse(ViewData["Next"].ToString()) + 10);
                                        for (int i = (int.Parse(ViewData["Pre"].ToString()) - 10) > 0 ? (int.Parse(ViewData["Pre"].ToString()) - 10) : 1; i < pagecount; i++)
                                        { 
                                        <a class="btn" href="/admin/articles?PageIndex=@i@ViewData["CID"]@ViewData["UserID"]">
                                            @i.ToString()
                                        </a>
                                        }

                                    }
                                    <a class="btn" href="/admin/articles?PageIndex=@ViewData["Next"]@ViewData["CID"]@ViewData["UserID"]">
                                        <i class="icon-forward"></i></a><a class="btn" href="/admin/articles?PageIndex=@ViewData["PageCount"]@ViewData["CID"]@ViewData["UserID"]">
                                            <i class="icon-step-forward"></i></a>
                                </div>
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $(".recommand").click(function () {
            $.post("/Admin/ArticlesRecommad", { ID: $(this).attr("data-id") }, function (dataresult) {
                location.reload();
            })
        });
        $(".release").click(function () {
            $.post("/Admin/ArticlesRelease", { ID: $(this).attr("data-id") }, function (dataresult) {
                location.reload();
            })
        });
        $(".delete").click(function () {
            $.post("/Admin/ArticlesDel", { ID: $(this).attr("data-id") }, function (dataresult) {
                location.reload();
            })
        });
        $("#btnSearch").click(function () {
            location.href = "/Admin/Articles/?keyword=" + $("#searchTitle").val();
        });
    })

</script>
